package com.ymh.git.thread.juc;

import java.util.concurrent.ExecutionException;

/**
 * 如何中断线程
 * Created by aivin on 2018/10/28.
 */
public class EndRunnable {

    private static class MyRunnable implements Runnable {

        @Override
        public void run() {
            while (!Thread.currentThread().isInterrupted()) { //判断线程是否中断
                System.out.println(Thread.currentThread().getName() + "extends Thread");
            }
            System.out.println(Thread.currentThread().getName() + " interrupt flag is: " + Thread.currentThread().isInterrupted());
        }
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyRunnable myRunnable = new MyRunnable();
        Thread myThread = new Thread(myRunnable, "myRunnable");
        myThread.start();
        Thread.sleep(20);
        myThread.interrupt();// 中断线程
    }
}
